package com.datastructure.test.lengthofchildchar.self;

public class MaxSameOfTwoChar {

    public static void main(String[] args) {

    }

    public String getMaxSameOfTwoChar(String s1,String s2){
        int index = 0;
        int maxLength = 0;
        for (int i = 0; i < s2.length(); i++) {
            for(int j = i+1;j<s2.length();j++){
                if(s1.contains(s2.substring(i,j))){
                    maxLength=Math.max(i-j,maxLength);
                    index = i;
                }
            }
        }
        if(maxLength==0){
            return "-1";
        }
        return s1.substring(index,index+maxLength);
    }
}
